from datetime import datetime
from typing import Dict, Any, Optional
import uuid
from enum import Enum


class ContentType(str, Enum):
    TEXT = "text"
    IMAGE = "image"
    AUDIO = "audio"
    VIDEO = "video"


class Role(str, Enum):
    USER = "user"
    ASSISTANT = "assistant"
    SYSTEM = "system"


class MemoryRecord:
    def __init__(
            self,
            user_id: str,
            saas_id: str,
            content: str,
            type: str,
            sec_type: str,
            optimized_content: Optional[str] = None,
            happen_time: Optional[str] = None,
            title: Optional[str] = None,
            relation: Optional[str] = None,
            detail: Optional[str] = None,

    ):
        self.id = str(uuid.uuid4())
        self.user_id = user_id
        self.saas_id = saas_id
        self.content = content
        self.type = type
        self.sec_type = sec_type
        self.timestamp = datetime.now().isoformat()
        self.optimized_content = optimized_content
        self.happen_time = happen_time
        self.title = title
        self.relation = relation
        self.detail = detail


    def to_dict(self) -> Dict[str, Any]:
        return {
            "id": self.id,
            "user_id": self.user_id,
            "saas_id": self.saas_id,
            "type": self.type.value,
            "sec_type": self.sec_type.value,
            "content": self.content,
            "relation": self.relation,
            "timestamp": self.timestamp,
            "optimized_content": self.optimized_content,
            "happen_time": self.happen_time,
            "title": self.title,
            "detail": self.detail,

        }

    @property
    def memory_content(self) -> str:
        if self.content_des:
            return f"{self.role}: {self.content} (描述: {self.content_des})"
        return f"{self.role}: {self.content}"